package com.tac.service.wms.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.wms.MaterialDao;
import com.tac.pojo.wms.Material;
import com.tac.service.wms.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MaterialServiceImpl implements MaterialService {

    @Autowired
    private MaterialDao materialDao;

    //查看物料列表
    public Result<PageInfo<Material>> getList(Integer pageNum,Integer pageSize,Integer typeId, Integer code, String name, String model, String specifications){
        PageHelper.startPage(pageNum,pageSize);
        List<Material> list = materialDao.getList(typeId, code, name, model, specifications);
        PageInfo<Material> materialPageInfo = new PageInfo<>(list);
        return Result.success(materialPageInfo);
    }


    public Result save(Material material){
        Integer integer = materialDao.save(material);
        if(integer<=0){
            return Result.error("添加失败");
        }
        return Result.success(null);
    }

    public Result remove(List<Integer> ids){
        Integer integer = materialDao.remove(ids);
        if(integer<=0){
            return Result.error("删除失败");
        }
        return Result.success(null);
    }

    public Result update(Material material){
        Integer integer = materialDao.update(material);
        if(integer<=0){
            return Result.error("修改失败");
        }
        return Result.success(null);
    }
}
